package spring.controller;

import java.io.BufferedReader;
import java.io.IOException;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import IOTWeb.com.utils.Utils;

@RestController
public class LoadClassController {
	
	@RequestMapping(value="/loadclass/{classname}/{classfun}", method = RequestMethod.POST)
	public String test(@PathVariable String classname, @PathVariable String classfun, HttpServletRequest request) throws Exception{
		Utils utils = new Utils();
		String res = "";
		
        BufferedReader reader = request.getReader();
        StringBuilder builder = new StringBuilder();
        String line = reader.readLine();
        while(line != null){
            builder.append(line);
            line = reader.readLine();
        }
        reader.close();
		String[] args= {classfun, line};
		res = utils.loadClass(classname, args);
		return res;
	}
}
